<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @package			RemaInventoryManagement
 * @subpackage	    PT. RemasysIndo
 * @category		Customized Version
 * @author			Jalu Ahmad Pambudi
 * @mail            j.a.pambudi@gmail.com
 * @copyright		
 * @license			http://remasysindo.com/
 * @link			http://remasysindo.com/remainv/
 */
 
 
class M_account extends DataMapper {
   var $table = 'chart_class';
   var $key = 'csection';
 function __construct() {
  parent::__construct();
  $this->tableHead = 'chart_class';
  $this->tableDetail='chart_master';
  
 }
 function getHead(){
  $sqlStatement = "SELECT distinct(a.account_class) as classid, b.class_name FROM " . $this->tableHead ;
  $sqlStatement .= " b left outer join ". $this->tableDetail . " a  on a.account_class = b.csection " ;
  $sqlStatement .= " where b.isactive = 1";
  $sqlResult = array();
  $sqlExecute = $this->db->query($sqlStatement);
  foreach ($sqlExecute->result() as $headRow) {
   $id = $headRow->classid;
   $sqlStatement = "SELECT * FROM " . $this->tableDetail . " where account_class ='" . $headRow->classid . "' and isactive =1 ";
   $sqlExDetail = $this->db->query($sqlStatement);
   $sqlResult[$id] = $sqlExDetail->result_array();
  }
  return $sqlResult;
 }
 
 function getTree() {
  $sqlResult = array();
  $sqlStatement = "Select * From account_class";
  $sqlExecute = $this->db->query($sqlStatement);
  foreach($sqlExecute->result() as $headRow) {
   $sqlResult[$headRow->csection] ="<tr><td>$headRow->csection</td><td>$headRow->class_name</td></tr>";
   $sqlStatement = "SELECT * from account_class FROM chart_master where pdt_status = 'H' and account_class = ".$headRow->csection ;
   $sqlExecute = $this->db-query($sqlStatement);
    foreach ($sqlExecute->result() as $parentRow) {
	 $sqlStatement = "SELECT * from account_class FROM chart_master where pdt_status <> 'H' and account_parent = ".$parentRow->account_code ;
     $sqlExecute = $this->db-query($sqlStatement);
	}
  }
 }
 
 function getAccClass() {
  $sqlStatement = "SELECT * FROM chart_class ";

  $sqlExecute = $this->db->query($sqlStatement);
  return $sqlExecute->result();
 }
 
 function getAccMainHead(){
  $sqlStatement = "SELECT * FROM chart_master WHERE chart_master.account_parent=chart_master.account_code ";
  
  $sqlExecute = $this->db->query($sqlStatement);
  return $sqlExecute->result();
 }
 
 function getAccParent(){
  $sqlStatement = "SELECT * FROM chart_master WHERE pdt_status = 'H' " ;
  
  $sqlExecute = $this->db->query($sqlStatement);
  return $sqlExecute->result();
 }
 
 function getAccMaster() {
	$sqlExecute = $this->db->get('chart_master');
	return $sqlExecute->result();
 }
}

?>